<?php
class JsonComponent extends Component
{
	
/**
Funcion para mostrar imagen el campo requerido
Esta Funcion recibe como parametros:
$ayuda: proxima a eliminar
$div: donde se va a mostrar la imagen
$mensaje: mensaje a mostrar si no se pasa queda como 'Requerido'
**/
		function monta_imagem($ayuda='vacio',$div,$mensaje='vacio') 
		{
			if($mensaje=='vacio')$mensaje='Requerido';
				$imagen='/css/tabs/images/default/form/exclamation.gif';
echo "<script type='text/javascript'>	document.getElementById('".$div."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\'>&nbsp;<b>$mensaje</b></font>'; </script>";
		}
function pr($array) {
$valor="<div id='div_pr'style='display:none;' align='center'><br />
<table border='2' cellpadding='5' cellspacing='5' width='90%' align='center'>
<tr bgcolor='#cccccc'><th width='50px'>&nbsp;<b>CAMPO</b></th><th>&nbsp;&nbsp;<b>VALOR</b></th></tr>";


foreach ($array as $key => $value) {
$valor.="<tr bgcolor='#ffffff'><td>&nbsp;$key</td><td>&nbsp;&nbsp;$value</td></tr>";
}
$valor.="</table>
<br />
</div>";

$valor.="
<script type='text/javascript'>
Ext.onReady(function() {
    Ext.create('Ext.window.Window', {
//        id : 'mensaje',
        title : 'IMPRESION DE DATA FORM [\$this->request->data]',
        layout: 'fit',
        width: '50%',
        height: '80%',
    	contentEl: 'div_pr',
        maximizable: true,
        collapsed: true,
        collapsible: true,
	modal: true,
	autoScroll: true,
        resizable: true,
        constrain: false
    }).show();

});

</script>";
$valor.="<script type='text/javascript'>document.getElementById('div_pr').style.display='block';</script>";


echo $valor;
//<img src='/img/ajax-loader_mini.gif'><font color='red'>Requerido</font>

}
function mensaje($ayuda='vacio',$mensaje,$titulo,$campo='vacio') {


if(!isset($mensaje))$mensaje='Indique un mensaje';
if(!isset($titulo))$titulo='MENSAJE';
$valor="
<script type='text/javascript'>
Ext.onReady(function() {
Ext.MessageBox.alert('".strtr(strtoupper($titulo),"àèìòùáéíóúçñäëïöü","ÀÈÌÒÙÁÉÍÓÚÇÑÄËÏÖÜ")."', '".ucwords(strtolower($mensaje))."', null);

});
</script>
";
if($campo!='vacio')
{
//$imagen='/css/tabs/images/default/form/exclamation.gif';
$imagen='/img/iconos/flecha/flecha_roja.png';
$valor.="<script type='text/javascript'>
//document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Error</b></font>';
//document.getElementById('".$campo."').focus();

</script>";
}


echo $valor;

}

function posicion($title){
echo "<script type='text/javascript'>document.getElementById('pasofuncionfilset').innerHTML='$title';</script>";
echo "<script type='text/javascript'>document.getElementById('pasofuncionfilset').style.display='block';</script>";
echo "<script type='text/javascript'>document.getElementById('title_navegador').innerHTML='$title / SISTEMA SIMA';</script>";
}


function title($ayuda='vacio',$title=''){
echo '<script type=\'text/javascript\'>document.getElementById(\'title_tabs_1\').innerHTML=\'<font style="font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 0.8em;font-weight:bold;" color="#08298A"><b>'.$title.'</b></font>\';</script>';
echo "<script type='text/javascript'>document.getElementById('title_navegador').innerHTML='$title / SISTEMA SIMA';</script>";
}

function tsesion($t=0){
if($t==1)
echo "<script type='text/javascript'>document.getElementById('msjsessioncerrada').innerHTML='<b>SU SESION A EXPIRADO !!!</b>';</script>";
else
echo "<script type='text/javascript'>document.getElementById('msjsessioncerrada').innerHTML='';</script>";

}

function empyt($ayuda='vacio',$empyt,$norequeridos=array(),$pre=0) {
$imagen='/css/tabs/images/default/form/exclamation.gif';
$valor=0;

foreach ($empyt as $key => $value) {
if (!in_array($key, $norequeridos)) {
if($value==null or $value==''or $value==' '){
//

	if($pre==1)
	{

			if(strpos($key,'_h')>0)
			{
//echo $key."<br />";
					echo "<script type='text/javascript'>
document.getElementById('".$key."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Requerido</b></font>';
</script>";
					$valor++;
			}
	}
	else
	{
		echo "<script type='text/javascript'>
document.getElementById('".$key."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Requerido</b></font>';
</script>";
		$valor++;
	}



//$imagen='/img/iconos/flecha/flecha_roja.png';

}
}

}

if ($valor>=1)$valor=true;else$valor=false;
return $valor;
//echo $valor;
}


function empyt_capa($ayuda='vacio',$empyt,$requeridos=null,$capa=null,$formulario=null) {
$valor=0;
//echo $requeridos;
foreach ($empyt as $key => $value) {
if (in_array($key, $requeridos)) {


if($value==null or $value==''or $value==' '){
//echo '<br />1-'.$value;
//echo "<script type='text/javascript'>alert('kkkkk');</script>";
//$imagen='/css/tabs/images/default/form/exclamation.gif';
$valor++;
}
}

}
//document.getElementById('".$key."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\'>&nbsp;<b>Requerido</b></font>';
if ($valor>=1)
{$valor=true;
if($capa=='capa1'){
	$this->activarcapa(1,$formulario);
}
else if($capa=='capa2'){
	$this->activarcapa(2,$formulario);
}
else if($capa=='capa3'){
	$this->activarcapa(3,$formulario);
}


}else{
$valor=false;


}
return $valor;
//echo $valor;
}

	public function activarcapa($tipo,$formulario=null)
        {
        if($tipo==1){


						//		$this->posicion('&nbsp;Paso 1/3');
					echo "<script type='text/javascript'>document.getElementById('title_filset_ventna').innerHTML=' / Datos Personales del Productor';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista3').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista2').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista1').style.display='block';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona1').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb1').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc1').style.display='block';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc2').style.display='none';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona3').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb3').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc3').style.display='none';</script>";


        }
        else if($tipo==2){
					echo "<script type='text/javascript'>document.getElementById('title_filset_ventna').innerHTML=' / Datos de Ubicacion de la Vivienda del Productor';</script>";
							//	$this->posicion('&nbsp;Paso 2/3');
       //         echo "<script type='text/javascript'>document.getElementById('vistainput').value='vista3';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista3').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista2').style.display='block';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista1').style.display='none';</script>";


		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona1').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb1').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc1').style.display='none';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona2').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb2').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc2').style.display='block';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona3').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb3').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc3').style.display='none';</script>";


        }
        else if($tipo==3){
					echo "<script type='text/javascript'>document.getElementById('title_filset_ventna').innerHTML=' / Datos de la Unidad Productiva del Productor';</script>";
							//$this->posicion('&nbsp;');
              //  echo "<script type='text/javascript'>document.getElementById('vistainput').value='guardar';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista3').style.display='block';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista2').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista1').style.display='none';</script>";


		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona1').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb1').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc1').style.display='none';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc2').style.display='none';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona3').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb3').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc3').style.display='block';</script>";


        }
				else if($tipo==4){
					echo "<script type='text/javascript'>document.getElementById('title_filset_ventna').innerHTML=' / Finalizar Registro';</script>";
					//			$this->posicion('&nbsp;Paso 3/3');
              //  echo "<script type='text/javascript'>document.getElementById('vistainput').value='guardar';</script>";
								echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista4').style.display='block';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista3').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista2').style.display='none';</script>";
                echo "<script type='text/javascript'>document.getElementById('".$formulario."xvista1').style.display='none';</script>";


		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona1').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb1').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc1').style.display='block';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb2').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc2').style.display='none';</script>";

		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttona3').style.display='none';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonb3').style.display='block';</script>";
		echo "<script type='text/javascript'>document.getElementById('".$formulario."buttonc3').style.display='none';</script>";


        }

}






	
function limpiar_empyt($ayuda='vacio',$empyt) {
$valor=0;
foreach ($empyt as $key => $value) {
//if (!in_array($key, $norequeridos)) {
if($value==null or $value==''){
echo "<script type='text/javascript'>
document.getElementById('".$key."_em').innerHTML='&nbsp;';
//document.getElementById('div_pr').style.display='none';
</script>";
$valor++;
//}
}

}
if ($valor>=1)$valor=true;else$valor=false;
return $valor;
//echo $valor;
}
function correo($ayuda='vacio',$email='vacio',$campo='vacio'){  
$imagen='/img/iconos/flecha/flecha_roja.png';
$valor="";
 
if($email=="sxixmxoxnx@gmail.com"){
$valor= true;
echo "<script type='text/javascript'>
document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>no pueder ser igual al ejemplo</b></font>';
//document.getElementById('".$campo."').focus();
</script>";
}
else if($email!=""){
if (preg_match('/^[A-Za-z0-9-_.+%]+@[A-Za-z0-9-.]+\.[A-Za-z]{2,4}$/', $email)) {
$valor= false;
}
else{
$valor= true;
echo "<script type='text/javascript'>
document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Ejemplo sxixmxoxnx@gmail.com</b></font>';
//document.getElementById('".$campo."').focus();
</script>";
}
}
else{
$valor= false;
}

return $valor;

}
function celular($ayuda='vacio',$celular='vacio',$campo='vacio'){  

$valor="";
if($celular!=""){
$codigos=array('0412','0414','0424','0416','0426');
$mensaje="";
$celulararray=explode('-',$celular);
$bf=0;
if(strlen($celular)<12){
$mensaje="Error Faltan digitos";
$valor= true;
$bf=1;
}
else if (!in_array($celulararray[0], $codigos)){
$mensaje="Error codigo no valido ";
$valor= true;
$bf=1;
}
else{
$valor= false;
}
if($bf==1){
//echo '>>>>>'.$campo."_em";
$imagen='/img/iconos/flecha/flecha_roja.png';
echo "<script type='text/javascript'>
document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>$mensaje</b></font>';
//document.getElementById('".$campo."').focus();
</script>";
}
}
else{
$valor= false;
}

return $valor;

} 




function telefono($ayuda='vacio',$telefono='vacio',$campo='vacio'){  

$valor="";
if($telefono!=""){
$codigos=array('0412','0414','0424','0416','0426');
$mensaje="";
$telefonoarray=explode('-',$telefono);
$bf=0;
if(strlen($telefono)<12){
$mensaje="Error Faltan digitos";
$valor= true;
$bf=1;
}/*
else if (!in_array($telefonoarray[0], $codigos)){
$mensaje="Error codigo no valido ";
$valor= true;
$bf=1;
}*/
else{
$valor= false;
}
if($bf==1){
//echo '>>>>>'.$campo."_em";
$imagen='/img/iconos/flecha/flecha_roja.png';
echo "<script type='text/javascript'>
document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>$mensaje</b></font>';
//document.getElementById('".$campo."').focus();
</script>";
}
}
else{
$valor= false;
}

return $valor;

} 


function verifica($model,$campodb,$dato,$campoinput,$id=NULL)
{
	
		if(isset($model) and isset($campodb) and isset($dato) and isset($campoinput))
		{
				$this->$model = ClassRegistry::init($model);
				if(isset($id))
				{
					$condiciones=array($model.'.id !='=>$id,"$model.$campodb"=>$dato);
				}
				else
				{
					$condiciones=array("$model.$campodb"=>$dato);
				}
				//$da = $this->Productor->find('first',array('fields'=>array('Productor.id'),'conditions'=>$condiciones));
		//if(isset($da['Productor']['id']) && $da['Productor']['id'] > 0 )
				$cant=$this->$model->find('count',array('conditions'=> $condiciones));
				if($cant==0) return false;
				else
				{
						$imagen='/img/iconos/flecha/flecha_roja.png';
						echo "<script type='text/javascript'>
document.getElementById('".$campoinput."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Error ya existe!</b></font>';</script>";
						return true;
				}
		}
		return true;
}

function verifica_dos($model,$campodb,$campodbdos,$dato,$datodos,$campoinput,$id=NULL)
	{
	
			if(isset($model) and isset($campodb) and isset($dato) and isset($campodbdos) and isset($datodos)  and isset($campoinput))
			{
					$this->$model = ClassRegistry::init($model);
					if(isset($id))
					{
						$condiciones=array($model.'.id !='=>$id,"$model.$campodb"=>$dato,"$model.$campodbdos"=>$datodos);
					}
					else
					{
						$condiciones=array("$model.$campodb"=>$dato,"$model.$campodbdos"=>$datodos);
					}
					//$da = $this->Productor->find('first',array('fields'=>array('Productor.id'),'conditions'=>$condiciones));
			//if(isset($da['Productor']['id']) && $da['Productor']['id'] > 0 )
					$cant=$this->$model->find('count',array('conditions'=> $condiciones));
					if($cant==0) return false;
					else
					{
							$imagen='/img/iconos/flecha/flecha_roja.png';
							echo "<script type='text/javascript'>
	document.getElementById('".$campoinput."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Error ya existe!</b></font>';</script>";
							return true;
					}
			}
			return true;
	}
	

function verifica_rif($model,$campodb,$dato,$campoinput,$id=NULL)
{
	//echo $campoinput;
		if(isset($model) and isset($campodb) and isset($dato) and isset($campoinput))
		{
				$cedulas=explode("-",$dato);
				if(!isset($cedulas[1]))$cedulas[1]=0;
				$this->$model = ClassRegistry::init($model);
				if(isset($id))
				{
					$condiciones=array($model.'.id !='=>$id,"$model.$campodb like "=>"%-".$cedulas[1]);
				}
				else
				{
					$condiciones=array("$model.$campodb like "=>"%-".$cedulas[1]);
				}
				//$da = $this->Productor->find('first',array('fields'=>array('Productor.id'),'conditions'=>$condiciones));
		//if(isset($da['Productor']['id']) && $da['Productor']['id'] > 0 )
				$cant=$this->$model->find('count',array('conditions'=> $condiciones));
				if($cant==0) return false;
				else
				{
						$imagen='/img/iconos/flecha/flecha_roja.png';
						echo "<script type='text/javascript'>
document.getElementById('".$campoinput."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Error ya existe!</b></font>';</script>";
						return true;
				}
		}
		return true;
}





function checkdate($ayuda='vacio',$fecha='00-00-0000',$campo='') {
$fecha=explode('-',$fecha);
if(!isset($fecha[0]))$mes='00';else$mes=$fecha[0];
if(!isset($fecha[1]))$dia='00';else$dia=$fecha[1];
if(!isset($fecha[2]))$ani='00';else$ani=$fecha[2];

if(strlen($ani)==4){
if($ani<1900 or $ani>(date('Y')+100))$ani='00';
$valor=checkdate($dia,$mes,$ani);
if($valor==true)
$valor=false;
else{
$valor=true;
$imagen='/img/iconos/flecha/flecha_roja.png';
echo "<script type='text/javascript'>
document.getElementById('".$campo."_em').innerHTML='&nbsp;<img src=\'$imagen\' width=\'13px\' height=\'13px\'><font color=\'red\' style=\'cursor:pointer;\'>&nbsp;<b>Error Fecha no Valida</b></font>';
//document.getElementById('".$campo."').focus();
</script>";
}
}else{
$valor=true;
}
return $valor;
}






function guardando($ayuda='vacio',$mensaje='',$div='guardandoform') {

echo $valor="<style type='text/css'>
.x-message-box .ext-mb-download {
    background: url('../img/guardar/download.gif') no-repeat scroll 6px 0px transparent;
    height: 52px!important;
}
</style>

<script type='text/javascript'>

Ext.require([
    'Ext.window.MessageBox',
    'Ext.tip.*'
]);

Ext.onReady(function(){

        Ext.MessageBox.show({
           msg: 'Guardando por Favor Espere...<br ><br >&nbsp;&nbsp;$mensaje  <br >',
           progressText: 'Guardando...',
           width:300,
           wait:true,
           waitConfig: {interval:100},
           icon:'ext-mb-download', //class declarada arriba
           animateTarget: '$div'
       });
        setTimeout(function(){

            Ext.MessageBox.hide();
          //  Ext.MessageBox.msg('Done', 'Your fake data was saved!');
        }, 3000);
});

</script>";

}





}


